﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using TigerAndGoats.Control;
using TigerAndGoats.Framework;
using TigerAndGoats.Resources;

namespace TigerAndGoats.Sprites
{
    public class DestinationTip: Piece
    {
        public DestinationTip()
        {
            this._image = new System.Drawing.Bitmap(@"Resources\destinationTip.png");
        }

        public Piece FromPiece { get; set; }

        public override void Draw(Graphics graphics)
        {
            if (_location != null)
            {
                graphics.DrawImage(_image, new Rectangle(
                    GetPieceLocation(GetPointByOrdinate(_location.GetOrdinate())
                    , GlobalSettings.PieceSizeGoat())
                    , GlobalSettings.PieceSizeGoat()
                    )
                );
            }
        }

        public virtual void WalkToHere()
        {
            // 放下棋子（这个时候目标位置也会被清空，以及目标位置脱离绑定，不显示出来）
            FromPiece.PutDown();
            // 这个棋子原来所在位置放弃这个棋子的显示
            FromPiece.GetLocation().SetPieceEmpty();
            // 棋子移动到新的位置
            this._location.SetPiece(FromPiece);

            // 羊走完了，老虎走
            GameControl.currentRound = GameControl.Round.Tiger;
            
            if (FromPiece is Goat)
            {
                // 记录羊的步数，从而确定老虎的胜利
                GameControl.GoatsSteps++;
                if (GameControl.GoatsSteps > GlobalSettings.MAX_GOATS_STEPS)
                {
                    GameControl.WinGame(UITipText.TIGER_WIN);
                    return;
                }

                // 提前判断 老虎是否有路可走
                int? tigerNextSteps = GameControl.TigerA.SetCurrentActualReachablePaths();
                if (tigerNextSteps > 0)
                {
                    GameControl.SetGeneralTip(UITipText.GAME_CONTINUE_WITH_MOVE_TIGER);
                }
            }

            ChequerGraph.RefreshUI();
        }
    }
}
